package edu.nf.postlikework.service.impl;

import edu.nf.postlikework.mapper.PostMapper;
import edu.nf.postlikework.model.dto.PostDTO;
import edu.nf.postlikework.model.entity.Post;
import edu.nf.postlikework.service.LikeService;
import edu.nf.postlikework.service.PostService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author zjl
 * @date 2025/10/13
 */
@Service
@RequiredArgsConstructor
public class PostServiceImpl implements PostService {
    private final PostMapper postMapper;
    private final LikeService likeService;
    @Override
    public List<PostDTO> postList(Integer pageNum, Integer pageSize,Integer userId) {
        // 创建postVO集合
        List<PostDTO> postDTOList = new ArrayList<>();
        List<Post> posts = postMapper.postList(pageNum, pageSize);
        posts.forEach(post -> {
            PostDTO postDTO = new PostDTO();
            postDTO.setPost(post);
            Boolean like = likeService.isLike(post.getPostId(),userId);
            postDTO.setLike(like);
            postDTOList.add(postDTO);
        });
        return postDTOList;
    }
}
